package wsz.delay;

import com.alibaba.rocketmq.client.producer.DefaultMQProducer;
import com.alibaba.rocketmq.client.producer.SendResult;
import com.alibaba.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;

/**
 * 发送延迟消息
 * @author wsz
 * @date 2022/2/28 9:54
 **/
public class DelayProducer {
    public static void main(String[] args)  throws Exception{
        DefaultMQProducer producer = new DefaultMQProducer("producer_grp_wsz");
        producer.setNamesrvAddr("192.168.174.138:9876");
        producer.start();

        // 消息
        for (int i = 0; i < 8; i++) {
            Message message = new Message(
                    "tp_demo_06",
                    ("tp_demo_06 " + i).getBytes(StandardCharsets.UTF_8)
            );
            // 设置延迟等级
            message.setDelayTimeLevel(i);
            SendResult send = producer.send(message);
            System.out.println(send);
        }
        producer.shutdown();
    }
}
